//
//  FangDaView.m
//  放大镜例子
//
//  Created by CHL on 16/10/20.
//  Copyright © 2016年 杜甲. All rights reserved.
//

#import "MagnifierView.h"

@implementation MagnifierView

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // make the circle-shape outline with a nice border.
        
        self.layer.borderColor = [[UIColor lightGrayColor] CGColor];//设置边框
        self.layer.borderWidth = 3;
        self.layer.cornerRadius = 40;
        self.layer.masksToBounds = YES;
    }
    return self;
}

-(void)setTouchPoint:(CGPoint)touchPoint{
//    改变自己的center
    _touchPoint = touchPoint;
    // whenever touchPoint is set,
    // update the position of the magnifier (to just above what's being magnified)
    self.center = CGPointMake(touchPoint.x+60, touchPoint.y-40);
}


- (void)drawRect:(CGRect)rect {
    // here we're just doing some transforms on the view we're magnifying,
    // and rendering that view directly into this view,
    // rather than the previous method of copying an image.
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5));
    CGContextScaleCTM(context, 1.5, 1.5);
    CGContextTranslateCTM(context,-1*(_touchPoint.x),-1*(_touchPoint.y));
    
    [self.viewToMagnify.layer renderInContext:context];
}


@end
